{ ----------------------------------------------------------------------------
  Amstrad Notepad emulator
  Copyright (c) Michael Nixon (Zipplet) 2011.
  http://www.zipplet.co.uk/
  Licensed under the MIT license, please see mit_license.txt in the
  documentation directory.

  Z80 CPU emulation core
  ---------------------------------------------------------------------------- }
unit cpuz80;

interface

uses classes, globals, notepadstate;

type
  rcpuregs = record
    a: byte;            { Accumulator }
    f: byte;            { Flags }
    b: byte;
    c: byte;
    d: byte;
    e: byte;
    h: byte;
    l: byte;
  end;
  pcpuregs = ^rcpuregs;

  eOpcodeHandler = procedure(opcode: byte) of object;

  tcpuz80 = class(tobject)
    private
      { Emulation state object }
      hState: tnotepadstate;

      { Function pointers to opcode handlers }
      opcode: array[0..255] of eOpcodeHandler;

      { Opcode handlers }
      procedure opcodeDummy(opcode: byte);
    protected
    public
      { ----------------------------------------------------------------------
        CPU state
        ---------------------------------------------------------------------- }
      { Pointer to current set of main regs }
      reg: pcpuregs;

      { Main register sets }
      reg_main, reg_shadow: rcpuregs;

      reg_i: byte;        { Interrupt vector }
      reg_r: byte;        { Refresh counter }
      { Seven bits of this 8-bit register are automatically incremented after
        each instruction fetch. The eighth bit remains as programmed, resulting
        from an LD R, A instruction. }
      reg_ix: word;       { Index register }
      reg_iy: word;       { Index register }
      reg_sp: word;       { Stack pointer }
      reg_pc: word;       { Program counter }

      constructor Create(stateobject: tnotepadstate);
      destructor Destroy; override;

      procedure reset;
  end;

implementation

uses sysutils;

{ ----------------------------------------------------------------------------
  Hard reset CPU
  ---------------------------------------------------------------------------- }
procedure tcpuz80.reset;
begin
end;

{ ----------------------------------------------------------------------------
  tcpuz80 constructor
  ---------------------------------------------------------------------------- }
constructor tcpuz80.Create(stateobject: tnotepadstate);
var
  i: longint;
begin
  inherited Create;
  {}
  self.hState := stateobject;

  { Assign opcodes }
  for i := 0 to 255 do begin
    self.opcode[i] := self.opcodeDummy;
  end;
end;

{ ----------------------------------------------------------------------------
  tcpuz80 destructor
  ---------------------------------------------------------------------------- }
destructor tcpuz80.Destroy;
begin
  {}
  inherited Destroy;
end;

{ ----------------------------------------------------------------------------
  Dummy opcode
  ---------------------------------------------------------------------------- }
procedure tcpuz80.opcodeDummy(opcode: byte);
begin
  {$ifdef debug}
  writeln('tcpuz80.opcodeDummy: $' + inttohex(opcode, 2));
  {$endif}
end;

end.
